using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimeManager : MonoBehaviour
{
    public Image timeBarFront;
    public ScoreManager scoreManager;
    public static bool isGameOver = false;  
    
    public static float curTime = 0;
    
    public static float curMaxTime = 3;

    private void Update() {
        curTime += Time.deltaTime;
        if (GameMod.GameMode == 0)
        {
            CheckCurMaxTime();
        }
        timeBarFront.fillAmount = (curMaxTime - curTime) / curMaxTime;
        GameOver();
    }

    public void GameOver()
    {
        if (curMaxTime - curTime <= 0)
        {
            Time.timeScale = 0.5f;
            isGameOver = true;
        }
    }

    private void CheckCurMaxTime()
    {

        float cur_score = scoreManager.GetScore();
        curMaxTime = curMaxTime - cur_score * 0.07f;
        if (curMaxTime < 2.5f)
        {
            curMaxTime = 2.5f;
        }
    }

}